#include <iostream>
#include <vector>
using namespace std;

// 全局变量存储中间值
int xpmclzjkln;

// 查找并替换序列
void replaceSequence(vector<int>& seq, const vector<int>& findSeq, const vector<int>& replaceSeq) {
    int n = seq.size();
    int m = findSeq.size();
    for (int i = 0; i <= n - m; ++i) {
        bool match = true;
        for (int j = 0; j < m; ++j) {
            if (seq[i + j] != findSeq[j]) {
                match = false;
                break;
            }
        }
        if (match) {
            xpmclzjkln = i;
            vector<int> newSeq;
            for (int k = 0; k < i; ++k) {
                newSeq.push_back(seq[k]);
            }
            for (int num : replaceSeq) {
                newSeq.push_back(num);
            }
            for (int k = i + m; k < n; ++k) {
                newSeq.push_back(seq[k]);
            }
            seq = newSeq;
            return;
        }
    }
}

// 插入平均数
void insertAverage(vector<int>& seq) {
    vector<int> newSeq;
    int n = seq.size();
    for (int i = 0; i < n; ++i) {
        newSeq.push_back(seq[i]);
        if (i < n - 1 && (seq[i] + seq[i + 1]) % 2 == 0) {
            xpmclzjkln = (seq[i] + seq[i + 1]) / 2;
            newSeq.push_back(xpmclzjkln);
        }
    }
    seq = newSeq;
}

// 翻转指定区间的序列
void reverseSubsequence(vector<int>& seq, int l, int r) {
    l--; r--;
    while (l < r) {
        swap(seq[l], seq[r]);
        l++;
        r--;
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> seq(N);
    for (int i = 0; i < N; ++i) {
        cin >> seq[i];
    }

    for (int i = 0; i < M; ++i) {
        int op;
        cin >> op;
        if (op == 1) {
            int L1;
            cin >> L1;
            vector<int> findSeq(L1);
            for (int j = 0; j < L1; ++j) {
                cin >> findSeq[j];
            }
            int L2;
            cin >> L2;
            vector<int> replaceSeq(L2);
            for (int j = 0; j < L2; ++j) {
                cin >> replaceSeq[j];
            }
            replaceSequence(seq, findSeq, replaceSeq);
        } else if (op == 2) {
            insertAverage(seq);
        } else if (op == 3) {
            int l, r;
            cin >> l >> r;
            reverseSubsequence(seq, l, r);
        }
    }

    for (int i = 0; i < seq.size(); ++i) {
        if (i > 0) {
            cout << " ";
        }
        cout << seq[i];
    }
    cout << endl;

    return 0;
}    